package com.flyou.ccnucenter.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 * ============================================================  
* 项目名称：androidTools   
* 
* 类名称：AppUtils   
* 
* 类描述：   应用相关工具类
*        1.获得应用名
*        2.获得应用版本号
* 
* 创建人：flyou  
* 
* 创建时间：2015-3-31 下午12:08:58  
*  
* 修改备注：   
* 
* 版本：@version    
*   ============================================================
 */
public class AppUtils {

  private AppUtils() {
    /* cannot be instantiated */
    throw new UnsupportedOperationException("cannot be instantiated");

  }

  /**
   * 获取应用程序名称
   */
  public static String getAppName(Context context) {
    try {
      PackageManager packageManager = context.getPackageManager();
      PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
      int labelRes = packageInfo.applicationInfo.labelRes;
      return context.getResources().getString(labelRes);
    } catch (NameNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }

  /**
   * [获取应用程序版本名称信息]
   * 
   * @param context
   * @return 当前应用的版本名称
   */
  public static String getVersionName(Context context) {
    try {
      PackageManager packageManager = context.getPackageManager();
      PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
      return packageInfo.versionName;

    } catch (NameNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }

}
